package com.example.librarymanagementsystembackend.systemicfunctions.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Value("${resource-dir}")
    private String resourceDir;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 拼接完整路径，注意 Windows 路径转义，确保以 file: 开头，目录正确
        String location = "file:" + resourceDir.replace("\\", "/");
        // 配置 /upload/** 路径映射到实际存储目录
        registry.addResourceHandler("/upload/**")
                .addResourceLocations(location);
    }
}

